using UnityEngine;
using System.Collections;

public class PlayerController : MonoBehaviour {
	public GameObject player;
	public GameObject mainCamera;
	//public TraukinioIlipimas ;
	float speed = 50;


	// Use this for initialization
	void Start () {
		
	}
	
	// Update is called once per frame

    void Update() {
        CharacterController controller = player.GetComponent<CharacterController>();
        TraukinioIlipimas trainEntry = player.GetComponent<TraukinioIlipimas>();
        TrainController trainController = mainCamera.GetComponent<TrainController>();
        ArrayList trains = trainController.trains;

        if (controller != null) 
        	Debug.Log("Print ok");
        else Debug.Log("Print bad");

            Vector3 deltaPos = new Vector3(0, 0, 0);

            if (trainEntry.insideTrain && trainController.trainStopped) //!((Train)trainController.trains[1]).isDriving)
            	deltaPos.x = ((Train)trains[1]).speed  * ((Train)trains[1]).dir * Time.deltaTime;

        //if (controller.isGrounded) {

			if (Input.GetKey("w"))
				deltaPos.y += Time.deltaTime * speed;
			if (Input.GetKey("a"))
			{
				deltaPos.x += -Time.deltaTime * speed;
				//player.transform.localScale.x
			}
			if (Input.GetKey("s"))
				deltaPos.y += -Time.deltaTime * speed;
			if (Input.GetKey("d"))
				deltaPos.x += Time.deltaTime * speed;

	            
      //  }
        //moveDirection.y -= gravity * Time.deltaTime;
        controller.Move(deltaPos);

    }



	void NotUpdate () {
	//	if (player.collider.OnCollisionEnter())


		Vector3 deltaPos = new Vector3(0, 0, 0);
		if (Input.GetKey("w"))
			deltaPos.y = -Time.deltaTime * speed;
		if (Input.GetKey("a"))
			deltaPos.x = Time.deltaTime * speed;
		if (Input.GetKey("s"))
			deltaPos.y = Time.deltaTime * speed;
		if (Input.GetKey("d"))
			deltaPos.x = -Time.deltaTime * speed;
		player.transform.Translate(deltaPos);
	}
}
